<?php

/**
 * 培训控制器
 * @author yanghao <yh38615890@sina.cn>
 * @date 07-04-12
 * @copyright (c) gandianli
 */

namespace app\api\controller;

use app\api\Base;
use think\Config;
use think\Db;
use think\exception\HttpException;
use com\gdl\newagk\dataobject\paper\PaperResultDTO;
use com\gdl\newagk\interfaces\PaperServiceClient;

class Paper extends Base
{
	 public function index() {
		exit;
    }
	/*******模拟考试*******/
	public function mockExam(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$basicid = $this->request->param('basic') ? $this->request->param('basic/d') : 0;
		$page = $this->request->param('page')>1 ? $this->request->param('page/d') : 1;
		$pagesize = $this->request->param('pagesize')>0 ? $this->request->param('pagesize/d') : 10;
		$title = $this->request->param('title') ? getStr($this->request->param('title'), 'string') : '';
		$plaformId = $this->request->param('plaformId') ? $this->request->param('plaformId/d') : 0;

		$labeid	= $this->request->param('labeid') ? getStr($this->request->param('labeid'), 'string') : '';
		if(!$identity_id || !$plaformId){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
            $Paper->num = $pagesize;
			$Paper->id = $plaformId;
			
			$Paper->filename['page'] = $page;
			$Paper->filename['title'] = $title;
			$Paper->filename['labeid'] = $labeid;
			
			if($basicid){
				$Paper->basicid = $basicid;
	
				$result = $api->formalExam($Paper);

				if(empty($result->data)){
					$data =  ['msg'=>$result->message,'code'=>'200','data'=>[]];
				} else {
					$data =  ['msg'=>'拉取列表成功','code'=>'200','data'=>$result->data];
				}
			} else {
				$result = $api->mockExam($Paper);
		
				if(empty($result->data)){
					$data =  ['msg'=>'拉取列表成功','code'=>'200','data'=>[],'prompt'=>[]];
				} else {
					$data =  ['msg'=>'拉取列表成功','code'=>'200','data'=>$result->data,'prompt'=>json_decode($result->message,true)];
				}
				
			}
			
        } catch (Exception $ex) {
            $data = ['msg'=>'拉取列表失败','code'=>'400','data'=>[],'prompt'=>[]];
        }
        return json_encode($data);
	}
	
	//筛选列表
	public function filterList(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$plaformId = $this->request->param('plaformId') ? $this->request->param('plaformId/d') : 0;
		if(!$identity_id || !$plaformId){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
			$Paper->id = $plaformId;
            $result = $api->filterList($Paper);

			$data =  ['msg'=>'拉取成功','code'=>'200','data'=>json_decode($result->message,true)];
        } catch (Exception $ex) {
            $data = ['msg'=>'拉取失败','code'=>'400','data'=>[],'prompt'=>[]];
        }
        return json_encode($data);
	}
	

	//抽题生成试卷
	public function generate(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$plaformId = $this->request->param('plaformId') ? $this->request->param('plaformId/d') : 0;
		$basicid = $this->request->param('basicid') ? $this->request->param('basicid/d') : 0;
		$id = $this->request->param('id') ? $this->request->param('id/d') : 0;
		if(!$identity_id || !$plaformId || !$id){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
			$Paper->id = $id;
			$Paper->plaform_id = $plaformId;
			$Paper->basicid = $basicid;
            $result = $api->generate($Paper);

			if($result->code){
				$data =  ['msg'=>'生成成功','code'=>'200'];
			} else {
				$data =  ['msg'=>$result->message,'code'=>'400'];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'生成失败','code'=>'400'];
        }
        return json_encode($data);
	}


	//进入模拟考场
	public function enterExam(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$plaformId = $this->request->param('plaformId') ? $this->request->param('plaformId/d') : 0;
		$basicid = $this->request->param('basicid') ? $this->request->param('basicid/d') : 0;
		$status = $this->request->param('basicid') ? 1 : 2;
		if(!$identity_id || !$plaformId){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
			$Paper->plaform_id = $plaformId;
			$Paper->status = $status;//2表示模拟 1表示正式考试
			$Paper->basicid = $basicid;
            $result = $api->enterExam($Paper);

			if($result->code){
				$data =  ['msg'=>'成功','code'=>'200','data'=>json_decode($result->message,true)];
			} else {
				$data =  ['msg'=>'失败','code'=>'400','data'=>[]];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);
	}
	
	
	//模拟考试记录
	public function mockList(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$page = $this->request->param('page')>1 ? $this->request->param('page/d') : 1;
		$pagesize = $this->request->param('pagesize')>0 ? $this->request->param('pagesize/d') : 10;
		$title = $this->request->param('title') ? getStr($this->request->param('title'), 'string') : '';
		$plaformId = $this->request->param('plaformId') ? $this->request->param('plaformId/d') : 0;
		if(!$identity_id){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
            $Paper->num = $pagesize;
			$Paper->filename['page'] = $page;
			$Paper->filename['title'] = $title;
            $result = $api->mockList($Paper);
			if($result->code){
				if(empty($result->data)){
					$data =  ['msg'=>$result->message,'code'=>'200','data'=>[]];
				} else {	
					$data =  ['msg'=>'拉取列表成功','code'=>'200','data'=>$result->data];
				}
			} else {
				$data =  ['msg'=>$result->message,'code'=>'400','data'=>[]];	
			}
		
        } catch (Exception $ex) {
            $data = ['msg'=>'拉取列表失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);
	}
	
	//模拟考试记录
	public function mockListDetails(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$page = $this->request->param('page')>1 ? $this->request->param('page/d') : 1;
		$pagesize = $this->request->param('pagesize')>0 ? $this->request->param('pagesize/d') : 10;
		$pid = $this->request->param('pid') ? $this->request->param('pid/d') : 0;
		$plaformId = $this->request->param('plaformId') ? $this->request->param('plaformId/d') : 0;
		if(!$identity_id || !$pid){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
            $Paper->num = $pagesize;
			$Paper->id = $pid;
			$Paper->filename['page'] = $page;
			$Paper->filename['title'] = $title;

            $result = $api->mockListDetails($Paper);

			$data =  ['msg'=>'拉取列表成功','code'=>'200','data'=>$result->data];
        } catch (Exception $ex) {
            $data = ['msg'=>'拉取列表失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);
	}
	
	//模拟考试详情
	public function mockDetails(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$id = $this->request->param('id') ? $this->request->param('id/d') : 0;
		if(!$identity_id || !$id){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
			$Paper->id = $id;
            $result = $api->mockDetails($Paper);

			if($result->code){
				$data =  ['msg'=>'成功','code'=>'200','data'=>json_decode($result->message,true)];
			} else {
				$data =  ['msg'=>$result->message,'code'=>'400','data'=>[]];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);
	}
	

	//考试中提交答案
	public function record(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$answer = $this->request->param('answer') ? json_decode(htmlspecialchars_decode($this->request->param('answer')),true) : [];
		$basicid = $this->request->param('basicid') ? $this->request->param('basicid/d') : 0;

		if(!$identity_id || empty($answer)){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
			$Paper->id = $basicid;
			$Paper->username=json_encode($answer);
            $result = $api->record($Paper);
			if($result->code){
				$data =  ['msg'=>$answer,'code'=>'200'];
			} else {
				$data =  ['msg'=>$result->message,'code'=>'400'];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'提交失败','code'=>'400'];
        }
        return json_encode($data);
	}

	
	/*******模拟考试end*******/
	/*******正式考试*******/
	//考试前确认页面
	public function candInfor(){

		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$basicid = $this->request->param('basicid') ? $this->request->param('basicid/d') : 0;

		if(!$identity_id || !$basicid){
			$data = ['msg'=>'缺少参数','code'=>'500','data'=>[]];
			return json_encode($data);
		}
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
			$Paper->basicid = $basicid;
            $result = $api->candInfor($Paper);

			if($result->code){
				$data =  ['msg'=>'查询成功','code'=>'200','data'=>json_decode($result->message,true)];
			} else {
				$data =  ['msg'=>$result->message,'code'=>'400','data'=>[]];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'查询成功','code'=>'400','data'=>[]];
        }
        return json_encode($data);
	}
	
	
	//获取人脸识别配置
	public function regulars(){

		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$basicid = $this->request->param('basicid') ? $this->request->param('basicid/d') : 0;

		if(!$identity_id || !$basicid){
			$data = ['msg'=>'缺少参数','code'=>'500','data'=>[]];
			return json_encode($data);
		}
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
			$Paper->basicid = $basicid;
            $result = $api->regulars($Paper);

			if($result->code){
				$data =  ['msg'=>'查询成功','code'=>'200','data'=>json_decode($result->message,true)];
			} else {
				$data =  ['msg'=>$result->message,'code'=>'400','data'=>[]];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'查询成功','code'=>'400','data'=>[]];
        }
        return json_encode($data);
	}
	//考试记录列表
	public function formaList(){
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;

		$page = $this->request->param('page')>1 ? $this->request->param('page/d') : 1;
		$pagesize = $this->request->param('pagesize')>0 ? $this->request->param('pagesize/d') : 10;
		$title = $this->request->param('title') ? getStr($this->request->param('title'), 'string') : '';
		$plaformId = $this->request->param('plaformId') ? $this->request->param('plaformId/d') : 0;


		if(!$identity_id || !$plaformId){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->identity_id = $identity_id;
            $Paper->num = $pagesize;
			$Paper->id = $plaformId;
			$Paper->filename['page'] = $page;
			$Paper->filename['title'] = $title;
	
			$result = $api->formaList($Paper);
			if($result->code){
				if(empty($result->data)){
					$data =  ['msg'=>$result->message,'code'=>'200','data'=>[]];
				} else {
					$data =  ['msg'=>$result->message,'code'=>'200','data'=>$result->data];
				}
				
			} else {
				$data = ['msg'=>$result->message,'code'=>'400','data'=>[]];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'拉取列表失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);
	}
	/*******正式考试end*******/
	
	/*******考试通用*******/
	//交卷
	public function score(){
		
		$basicid = $this->request->param('basicid') ? $this->request->param('basicid/d') : 0;
		$identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;
		$terminal = $this->request->param('terminal') ? $this->request->param('terminal/d') : 0;
		$answer = $this->request->param('answer') ? json_decode(htmlspecialchars_decode($this->request->param('answer')),true) : [];
		$status = $this->request->param('status') ? $this->request->param('status/d') : 2;
		if(!$identity_id || !$terminal  || !$status){ //|| empty($answer) 允许交白卷

			$data = ['msg'=>'缺少参数，交卷失败','code'=>'500','data'=>[]];
			return json_encode($data);
		}
		//$data = ['msg'=>json_encode($answer),'code'=>'400','data'=>[]];
//return json_encode($data);
        try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
            $Paper->basicid = $basicid;
			$Paper->identity_id = $identity_id;
			$Paper->filename['terminal'] = $terminal;
			$Paper->filename['answer'] = json_encode($answer);
			$Paper->filename['status'] = $status;
            $result = $api->carryOut($Paper);

			if($result->code){
			$data =  ['msg'=>$result->message,'code'=>'200','data'=>$result->data[0]];
			} else {
				$data = ['msg'=>$result->message,'code'=>'400','data'=>[]];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'交卷失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);
    }

	//考试结果
	public function examResults(){
	
		$pid = $this->request->param('pid') ? $this->request->param('pid/d') : 0;
		$basicid = $this->request->param('basicid') ? $this->request->param('basicid/d') : 0;
		if(!$pid){
			$data = ['msg'=>'缺少参数','code'=>'500'];
			return json_encode($data);
		}
		 try {
			\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
			$Paper->basicid = $basicid;
			$Paper->plaform_id = $pid;
            $result = $api->examResults($Paper);

			if($result->code){
				$data =  ['msg'=>'成功','code'=>'200','data'=>json_decode($result->message,true)];
			} else {
				$data =  ['msg'=>'失败','code'=>'400','data'=>[]];
			}
        } catch (Exception $ex) {
            $data = ['msg'=>'失败','code'=>'400','data'=>[]];
        }
        return json_encode($data);
	}



/**************/
   
	
	public function getBasicInfo() {
        \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
        try {
            $identity_id = $this->request->param('identity_id') ? (int)$this->request->param('identity_id') : 0; //用户标识id
            $plaform_id = $this->request->param('plaform_id') ? (int)$this->request->param('plaform_id') : 0; //大平台id
			if (!$identity_id || !$plaform_id){
                return json_encode(['code'=>500,'msg'=>'缺少参数','data'=>null]);
            }

            $time = time();
            $Basicapi = new PaperServiceClient(null);
            \ApiClient::build($Basicapi);
			$Paper = new PaperRequestDTO();
			$Paper->plaformid = $plaform_id;
			$Paper->identity_id = $identity_id ;
            $basicRoomList = $Basicapi->BasicRoom($Paper); //修改 userid 为 identity_id

            if ($basicRoomList->code==0){
                return json_encode(['code'=>400,'msg'=>'没有数据','data'=>null]);
            }

            $basicRoomList = array_filter($basicRoomList->data);
            $basicList = [];
            $c = 0;
            $examid = '';
            $paperid = '';
            $arrs=[];
            foreach ($basicRoomList as $key=>$value){
                $arrs[$value['basicid']]=$value;
            }

            foreach ($arrs as $bk=>$bv){
                if ($bv['end_time'] < $time){//是否超时
                    continue;
                }
                $dd[0] = $bv;
                if ($this->getOverFlow($dd, $identity_id) == false){
                    continue;
                }
                $basicList[$bk] = $bv;
                if ($bv['start_time'] < $time && $time < $bv['end_time']){//判断当前时间是否在考试规定时间
                    $c++;
                    if ($c==1 && $c<2){
                        $examid = $bv['basicid'];
                        $paperid = $bv['paperid'];
                    }else{
                        $examid = 0;
                        $paperid = 0;
                    }
                    $basicList[$bk]['start_exam']=1;
                }else{
                    $basicList[$bk]['start_exam']=0;
                }

            }
        } catch (Exception $e) {
            return json_encode(['code'=>500,'msg'=>'发生异常','data'=>null]);
        }
        $result = [];
        if ($c==1){//如果只有一次待考试
            $result['one_exam'] = $examid;
            $result['one_paper'] = $paperid;
        }else{
            $result['one_exam'] = 0;
            $result['one_paper'] = 0;
        }
        if (empty($basicList)) {
            return json_encode(['code'=>400,'msg'=>'没有数据','data'=>null]);
        }
        /** 获取用户其他学习室的考试信息end   * */
        $result['basicList'] = $basicList?$basicList:'';
        return json_encode(['code'=>200,'msg'=>'查询成功','data'=>$result]);
    }
	
	/**
     * 判断用户是否参加了考试
     * @param $BasicSetting 考场设置  serialize序列化
     * @param $identity_id
     * @return bool
     */
    public function getOverFlow($BasicSetting, $identity_id) {

		\ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk','gdlAgkSdk'));
        //是否限制次数
		try {
			if ($BasicSetting[0]['examnumber']) { //true 没限制 false 限制了
				$overflow = false;
				$paperid = $BasicSetting[0]['paperid'];
				$number = array();

				if ($paperid) {
					$basicid = $BasicSetting[0]['basicid'];
					
					$ExamsPapers = new PaperServiceClient(null);
					\ApiClient::build($ExamsPapers);
					$Paper = new PaperRequestDTO();
					$Paper->paperid = $plaform_id;
					$Paper->identity_id = $identity_id;
					$Paper->basicid = $basicid;
					$num = $ExamsPapers->getExamUseNumber($Paper);

					$number['child'][$paperid] = $num->data[0][0];
					if (!isset($number['all'])) {
						$number['all'] = 0;
					}
					$number['all'] = intval($number['all']) + $num->data[0][0];
				}

				if ($number['all'] >= $BasicSetting[0]['examnumber']) {
					$overflow = true;
				}
				if ($overflow) {
					return false;
				} else {
					return true;
				}
			} else {
				return true;
			}
		} catch (Exception $e) {
            return false;
        }
    }
	
	
	//人脸识别

    public function faceRecognition() 
    {

        $identity_id = $this->request->param('identity_id') ? $this->request->param('identity_id/d') : 0;

        if (!$identity_id || !$_FILES['file']['name']) {
            $data = ['msg' => '缺少参数1223
			', 'code' => '500'];
            return json_encode($data);
        }

        if (empty($_FILES['file']['name'])) {
            $data = ['msg' => '没有上传图片', 'code' => '400'];
            return json_encode($data);
        }

        $faceSdk = strtolower('youtu');
        $faceType = 2;

        $tFaceType = [
            'PASS' => 60,
            'differ' => 30,
            'message1' => 1,
            'message2' => 2
        ];

        $result = \Qiniu::instance()->upload(); //七牛上传
        $address = $result[0]['key'];
        $address = Config::get('qiniu.QINIU_DOMAIN') . $address;

        $souce_image = file_get_contents($_FILES['file']['tmp_name']);

        //$faceImgA = base64_encode(file_get_contents($_FILES['file']['tmp_name']));
        $faceImgA = $address;

        /*         * *********************** */
        try {
            \ApiClient::init(Config::get('api.appid'), Config::get('api.secret'), 30, array('gdlApiSdk', 'gdlAgkSdk'));
            $api = new PaperServiceClient(NULL);
            \ApiClient::build($api);
            $Paper = new PaperResultDTO();
            $Paper->identity_id = $identity_id;
            $result = $api->collect($Paper);
            if (!$result->code) {
                $data = ['msg' => $result->message, 'code' => '400'];
                return json_encode($data);
            }
            $photo = json_decode($result->message, true);
            $faceImgB = '';
            if ($photo['vface'] == 2 && !empty($photo['photoCollect'])) {
                $faceImgB = base64_encode(file_get_contents($photo['photoCollect']));
                $faceImgB = $photo['photoCollect']; //如果优图才启用 URL
            }


            $Paper->filename['faceImgA'] = $faceImgA;
            $Paper->filename['faceImgB'] = $faceImgB;


            $Paper->filename['faceType'] = $faceType;
            $faceMessage = Config::get('message.face');
            $similarity = 0;
            $judgeResult = -1;
            //比对的两张照片同时不为空，才可以调用比对接口
            if (!empty($faceImgA) && !empty($faceImgB)) {
                $results = $api->identify($Paper);
                $similarity = $results->data[0]['similarity'];
                $judgeResult = $faceSdk == 'facevisa' ? $results->data[0]['result'] : $results->data[0]['errorcode'];
            } else {
                $remark = 'no source img';
                $similarity = 0;
            }
            /* $monitorInfo = [
              'identity_id' => $identity_id,
              'truename' => $photo['truename'],
              'source_img' => $photo['photo_collect'], //留底照片
              'similarity' => $similarity,
              'judge_result' => $judgeResult,
              'reason' => $faceMessage[$tFaceType['message2']],
              'face_sdk' => $faceSdk,
              'remark' => $remark,
              'create_time' => time(),
              ]; */

            if ($similarity >= $tFaceType['PASS'] || $judgeResult >= 2) {
                return json_encode(['code' => 200, 'msg' => '通过','data' =>['succ' => 1]]);
            } else {
                return json_encode(['code' => 200, 'msg' => '验证失败','data' =>['succ' => 0]]);
            }
        } catch (Exception $ex) {
            $data = ['msg' => '失败', 'code' => '400'];
        }
        return json_encode($data);
    }

}
